<?php
namespace app\common\model\admin;
use app\admin\model\Admin;
/**
 * 登录
 *
 * @author Administrator
 *
 */
class Login
{
	/**
	 * 登陆 设置session admin_id admin_username admin_token
	 * @param array $admin  管理员
	 * @return boolean
	 */
	public function login($admin)
	{
		$row =  Admin::where('username',$admin['username'])->find();
		//如果用户名 密码匹配,设置
		if(!is_null($row) && $row->password == md5(md5($admin['password']) . $row->salt) ){
			token_session('admin_id',$row->id);
			token_session('admin_username',$row->username);
			//更新
			$row->loginfailure = 0;
			$row->logintime = time();
			$row->loginip = request()->ip();
			$row->token = access_token();
			return $row->save();
		}
		return false;
	}

}
